function obtiene_http_request()
{
    var req = false;
try
  {    req = new XMLHttpRequest(); /* p.e. Firefox */  }
catch(err1)
  { 
  try
    {
     req = new ActiveXObject("Msxml2.XMLHTTP");
  /* algunas versiones IE */
    }
  catch(err2)
    {
    try
      {
       req = new ActiveXObject("Microsoft.XMLHTTP");
  /* algunas versiones IE */
      }
      catch(err3)
        {
         req = false;
        }
    }
  }
return req;
}
var miPeticion = obtiene_http_request();
//***************************************************************************************
function from(codigo, div,url){
		var mi_aleatorio=parseInt(Math.random()*99999999);//para que no guarde la p�gina en el cach�...
		var vinculo=url+"?codigo="+codigo+"&rand="+mi_aleatorio;
		//alert(vinculo);
		miPeticion.open("GET",vinculo,true);//ponemos true para que la petici�n sea asincr�nica
		miPeticion.onreadystatechange=miPeticion.onreadystatechange=function(){
               if(miPeticion.readyState==4)
               {       //alert(miPeticion.readyState);
                       if (miPeticion.status==200)
                       {   //alert(miPeticion.status);
                           //var http=miPeticion.responseXML;
                           var http=miPeticion.responseText;
                           document.getElementById(div).innerHTML= http;
                       }
               }
             }
                miPeticion.send(null);
            }
//************************************************************************************************
function limpiar()
{ 
    document.form.reset();	
}

function procesaAjax(ajax, capa){
    var capaContenedora = document.getElementById(capa);
    if(ajax.readyState==1){
        capaContenedora.innerHTML="Cargando...";
    }else if(ajax.readyState==4){
        if(ajax.status==200){
            document.getElementById(capa).innerHTML= ajax.responseText;            
        }else if(ajax.status==404){
            capaContenedora.innerHTML = "La dirección no existe";
        }else{
            capaContenedora.innerHTML = "Error: "+ajax.status;
        }
    }
}

function FAjax(url, capa, valores, metodo){
    var ajax = obtiene_http_request();
    
    if(metodo.toUpperCase()=='POST'){
        ajax.open('POST', url, true);
        ajax.onreadystatechange = function(){
            procesaAjax(ajax, capa);
        }
        ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        ajax.send(valores);
        return;
    }
    if(metodo.toUpperCase()=='GET'){
        ajax.open('GET', url, true);
        ajax.onreadystatechange = function(){
            procesaAjax(ajax, capa);
        }
        ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        ajax.send(null);
        return;
    }
}

function obtSubTotal(c){
    var result=0;
    if(c>=0){
        for(var i=0; i<=c; i++){
            var subtotal = document.getElementById("subtotal"+c).value;
            result = result+subtotal;
        }
        document.getElementById("p_subtotal").value=5;
    }else{
        document.getElementById("p_subtotal").value=5;
    }    
}
function mod(c){
        var sum=0;   
        for(var i=0; i<=c; i++){
            var subtotal=document.getElementById("subtotal"+i).value;
            sum = sum + parseFloat(subtotal);
        }        
        document.getElementById("p_subtotal").value=sum;          
        return sum;
}

function igv(c){
    var subt = mod(c);
    var igv = (parseFloat(subt)*0.18);
    document.getElementById("p_igv").value=igv;
    return igv;
}

function ptotal(c){
    var ptotal = (mod(c)+igv(c));
    document.getElementById("p_total").value=ptotal;
}

function suma(cont){
var c= cont;
var v1=document.getElementById('txtprecio'+c).value;
var v2=document.getElementById('txtcantidad'+c).value;

var suma=v1*v2;
document.getElementById("subtotal"+c).value=suma;
}